package com.ershijin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.server.authorization.config.ProviderSettings;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

@RestController
public class TestController {
    @Autowired
    private ProviderSettings providerSettings;

    @GetMapping("/hello")
    public String hello() {
        return providerSettings.toString();
    }

    @RequestMapping("/userinfo")
    public Object userinfo() {
        return SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }
}
